﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ShredTheLog.Common.MVVM;
using ShredTheLog.Api;
using ShredTheLog.Api.DataContracts;
using System.Windows.Input;
using System.Diagnostics.Contracts;

namespace ShredTheLog.ViewModels
{
    public sealed class UserSearchConditionsViewModel : ViewModelBase
    {
        public UserSearchConditionsViewModel(Action<UserSearchCommandParameter> okAction)
        {
            Contract.Requires(okAction != null);

            _okAction = okAction;
        }

        private Action<UserSearchCommandParameter> _okAction;

        public Language? KnownLanguage { get; set; }
        public Language? PracticingLanguage { get; set; }
        public bool? ChatsOnline { get; set; }
        public Country? Country { get; set; }
        public int? MinAge { get; set; }
        public int? MaxAge { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Location { get; set; }

        public bool IsWindowClosed
        {
            get { return _isWindowClosed; }
            set { _isWindowClosed = value; OnPropertyChanged(() => IsWindowClosed); }
        }
        private bool _isWindowClosed;

        private ICommand _okCommand;
        public ICommand OkCommand
        {
            get
            {
                if (_okCommand == null)
                {
                    _okCommand = new DelegateCommand(
                        () => 
                        {
                            var request = new UserSearchCommandParameter(KnownLanguage, PracticingLanguage, ChatsOnline, Country, MinAge, MaxAge, FirstName, LastName, Location);
                            _okAction(request); 
                            IsWindowClosed = true; 
                        });
                }
                return _okCommand;
            }
        }
    }
}
